﻿using Zero;

/// <summary>
/// 元素反应：感电
/// </summary>
public class ElementElectroCharged : IElementReaction
{
    private readonly IElementHolder _holder;
    private readonly ElementElectroChargedState _state;

    public ElementElectroCharged(IElementHolder holder, ElementElectroChargedState state)
    {
        _holder = holder;
        _state = state;
    }

    public void Reaction(TriggerElementData triggerElementData)
    {
        if (_holder.GetElementAura("雷").Gauge > 0f && triggerElementData.ElementType == ElementType.Water ||
            _holder.GetElementAura("水").Gauge > 0f && triggerElementData.ElementType == ElementType.Electric)
        {
            if (_state.IsStarted)
            {
                _state.Source = triggerElementData.Source;
            }
            else
            {
                ServiceLocator.Get<IWorldNumberService>()
                    .CreateElementReaction(_holder.Owner.transform.position, "感电");
                _state.Start(triggerElementData.Source);
            }
        }
    }
}